<?php

/**
 * 开放商户 - 固定提现修改功能使用示例
 */

require_once __DIR__ . '/../../../vendor/autoload.php';

use JLPay\Core\OrgConfig;
use JLPay\Core\DemoConfig;
use JLPay\Services\Openmerch\Change\ChangeService;
use JLPay\Models\Openmerch\Change\FixedWithdrawModifyRequest;
use JLPay\Utils\Logger;
use JLPay\Utils\DemoRequestHandler;

// =================== 日志配置 =====================
$logger = Logger::getInstance();

// =================== 工具函数 =====================
function createConfig(): OrgConfig
{
    return DemoConfig::createConfigWithCrypto();
}

// =================== 数据构建函数 =====================
function buildFixedWithdrawModifyRequest(): FixedWithdrawModifyRequest
{
    $request = new FixedWithdrawModifyRequest();
    
    // 设置请求参数
    $request->setOrgNo("50720711")           // 机构号
            ->setMerchNo("849584358140108")  // 商户号
            ->setApplyId("b8659ea518d14c99b78b5ad000a0810E")  // 申请单id
            ->setOperateType("1")            // 设置方式，0-取消1-设置
            ->setWithdrawTimeList(["180000"]); // 定点清算时间列表
    
    return $request;
}

// =================== 示例函数 =====================
function fixedWithdrawModifyDemo(): void
{
    global $logger;

    $logger->info("开始执行固定提现修改示例");
    
    // 创建配置对象和变更服务
    $config = createConfig();
    $changeService = new ChangeService($config);
    
    // 创建固定提现修改请求
    $request = buildFixedWithdrawModifyRequest();
    
    // 发送请求 - 使用DemoRequestHandler
    $response = DemoRequestHandler::sendRequestAndHandleResponse(
        $changeService, 
        $request, 
        "固定提现修改",
        function($service, $request) {
            return $service->modifyFixedWithdraw($request);
        }
    );
    
    // 处理响应结果
    if ($response && $response->isSuccess()) {
        $logger->info("响应报文：" . json_encode($response->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
    }
    
    $logger->info("固定提现修改示例执行完毕");
}

// =================== 主程序 =====================
$logger->info("=" . str_repeat("=", 50));
$logger->info("===== 固定提现修改示例 开始 =====");
$logger->info("=" . str_repeat("=", 50));

fixedWithdrawModifyDemo();

$logger->info("=" . str_repeat("=", 50));
$logger->info("===== 固定提现修改示例执行完毕 =====");
$logger->info("=" . str_repeat("=", 50)); 